﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WebStudio.Business.Rule;
using WebStudio.Business.Entity;

public partial class Admin_MessageMge : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {
        if (Session["Admin_User"] == null || Session["Admin_User"].ToString() == "")
        {
            Response.Redirect("~/Admin/Login.aspx");
        }
        if (!Page.IsPostBack)
        {
            InitPage();
        }
    }

    private string strWhere
    {
        get
        {
            if (string.IsNullOrEmpty(Request.QueryString["status"]))
            {
                return "1=1";
            }
            else
            {
                int status = Convert.ToInt32(Request.QueryString["status"]);
                return "Status=" + status + "";
            }
        }
    }

    private void InitPage()
    {
        anpList.PageSize = 20;
        anpList.CurrentPageIndex = 1;
        anpList.RecordCount = MessageRule.GetMessageListCount(strWhere);
        rptMessageBind();
    }

    private void rptMessageBind()
    {
        rptMessage.DataSource = MessageRule.GetMessageList(anpList.CurrentPageIndex, anpList.PageSize, anpList.PageCount, anpList.RecordCount, strWhere);
        rptMessage.DataBind();
    }

    protected void rptMessage_ItemCommand(object source, RepeaterCommandEventArgs e)
    {
        if (e.CommandName == "delete")
        {
            LinkButton lbtnDelete = e.Item.FindControl("lbtnDelete") as LinkButton;
            MessageRule.DeleteMessageInfor(Convert.ToInt32(lbtnDelete.CommandArgument));
            rptMessageBind();
        }
        //if (e.CommandName == "reply")
        //{
        //    //LinkButton lbtnDelete = e.Item.FindControl("lbtnDelete") as LinkButton;
        //    //bMessage.ModifyMessageStatus(Convert.ToInt32(lbtnDelete.CommandArgument), 2);
        //    //rptMessageBind();
        //}
    }

    protected void anpList_PageChanged(object sender, EventArgs e)
    {
        rptMessageBind();
    }
}
